
import java.io.*;
import java.lang.*;

public class Main {

    public static void main(String[] args) {
        String chattest = "2我1我31啊12";
        String a = "啊";
        int inputNumber = 5;
        Main main=new Main();
        //
        main.check_string(chattest,inputNumber);

        Employee alex=new Employee("黄江宇",1,"男",100);
        System.out.println(alex.getName()+" "+alex.getSex()+" "+alex.getAge()+" "+alex.getSalary());
        alex.play();
        alex.sing();
        Manager blex=new Manager("红江宇",2,"男男",1100);
        System.out.println(blex.getName()+" "+blex.getSex()+" "+blex.getAge()+" "+blex.getSalary());
        blex.sing();
        blex.play();

    }

    public void check_string(String chattest, int inputNumber) {
        String result = "";
        int sum = 0;
        try {
            //3 2 2
//            System.out.println("UTF-8编码长度:" + a.getBytes("UTF-8").length);
//            System.out.println("GB2312编码长度:" + a.getBytes("GB2312").length);
//            System.out.println("GBK编码长度:" + chattest.getBytes("GBK").length);

            boolean tmp_bool = false;
            for (int i = 0; i < chattest.length(); i++) {
                String tmp = chattest.charAt(i) + "";
//
                //如果是汉字 到第二节
                if (tmp_bool == true) {
                    tmp_bool = false;
                    if (sum == inputNumber) {
                        break;
                    } else if (sum > inputNumber) {
                        result = result.substring(0, result.length() - 1);
                        break;
                    }
                    continue;
                }

                if (sum <= inputNumber && tmp_bool == false) {
                    if(sum==inputNumber)
                    {
                        //常规退出
                        break;
                    }
                    result += tmp;
                }

                //判断是否汉字
                if (tmp.getBytes("GBK").length == 2) {
                    sum += 2;
                    i--;
                    tmp_bool = true;
                } else {
                    sum++;
                }

            }
            System.out.println("Last result:" + result);
        } catch (Exception e) {
            //?
        }
    }
}

abstract class Role {
    protected String name;
    protected int age;
    protected String sex;
    public Role(String name,int age, String sex){
        this.name=name;
        this.age=age;
        this.sex=sex;
    }
    public Role(){

    }
    abstract public String getName();

    abstract public int getAge();

    abstract public String getSex();

    abstract public void setName(String name);

    abstract public void setAge(int Age);

    abstract public void setSex(String sex);
    abstract public void play();
}

class Employee extends Role {
    private int salary;
    public Employee(String name,int age, String sex,int salary)
    {
        super(name,age,sex);
        this.salary=salary;
    }
    public String getName() {
        return this.name;
    }

    public int getAge() {
        return this.age;
    }

    public String getSex() {
        return this.sex;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public void setAge(int age) {
        this.age = age;
    }
    public void setSalary(int salary)
    {
        this.salary=salary;
    }
    public int  getSalary(){
        return this.salary;
    }

    public void play() {
    //?
        System.out.println(this.name+"playing  game");
    }
    final  public void sing(){
        System.out.println(this.name + "can Singing");
    }
}
 class Manager extends Employee{
    final  private String vehicle="OFO";
    public Manager(String name,int age, String sex,int salary){
        super(name,age,sex,salary);
    }
    public void getVehicle(){
        System.out.println("开"+this.vehicle);
     }
 }